<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" href="css/common.css" type="text/css" />
        <link href="css/adminstyle.css" rel="stylesheet" type="text/css">
        <script src="js/jquery-1.6.2.min.js">
        </script>
        <title>
          <?=Common::_t('page_admin_area')?>
        </title>
    </head>
	<?
	  $teacher_id = Common::getGetStrValue('teacherId');
	  if($_SESSION['admin']['teacher_id']!=0){
			if(isset($teacher_id)&&$teacher_id>0){
				$teacher_id = $teacher_id;
			}else{
		  		$teacher_id = $_SESSION['admin']['teacher_id'];
			}
	  }
	  
	?>
    <body>
        <div id="man_zone">
            <div style="background-color:#FFFFFF ">
                <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1"
                class="tableborder" style="margin-top:8px;">
                <input type="hidden" value="<?=$teacher_id?>" id="teacherId" name="teacherId">
                <input type="hidden" id="checkbox_confirm_list" value="" id="checkbox_confirm_list">
                    <tr class="header">
                        <td colspan="8">
                            &nbsp;<?=Common::_t('ClassTimeSet')?>
                        </td>
                    </tr>
                    <tr bgcolor="#FFFFFF">
                        <td colspan="4" align="left">
                                	<?=Common::_t('course_arrage_info')?>
                                &nbsp;
                        </td>
                        <td colspan="4" align="right">
                             <?if(isset($_GET['teacherId'])){ ?>
                                	<input name="" type="button" class="PublicBot" value="<?=Common::_t('page_back');?>" onclick="javaScript:location.href='teacher_lists.html'"
                                />
                             <?} ?>                        
                        	<input class="PublicBot" name="" type="button" value="<?=Common::_t('page_save');?>" id="save_confirm">	
                            <? if (getParamValue( 'page')!=0) { ?>
                                <input class="PublicBot"  id="up_button"  name="" type="button" value="<?=getStr(Common::_t('page_roll'), 'up')?>" />
                                </A>
                                <? } else{ ?>
                                    <input class="PublicBot" id="next_button" name="" type="button" value="<?=getStr(Common::_t('page_roll'), 'next')?>"/>
                                    <? } ?>
                        </td>
                    </tr>
                    <tr bgcolor="#FFFFFF">
                        <td align="center">
                           <?=Common::_t('Time')?>
                        </td>
                        <? foreach($date as $v){ ?>
                      <td align="center">
                                <?=date( 'Y-m-d',$v)?><br/>
                           <?=Common::_t('All_Check')?><input type="checkbox" onClick="alls('<?=$v?>',this)"   <?if (count($courseTimeData[$v])==26){
						  	echo 'checked="checked"';
						  }
						  ?>  />
                        </td>
                            <? } ?>
                    </tr>
                    <? foreach ($time as $v){ ?>
                        <tr bgcolor="#FFFFFF">
                            <td align="center">
                                <?=$v['name']?>
                            </td>
                            <? foreach($date as $v1){ ?>
                            	<?$bgcolor="#FFFFFF";?>
                            <?if($courseTimeData[$v1][$v['time']]['confirm_status']==2){?>
                            	<?$bgcolor="#66CCCC";?>
                            <?}?>
                                <td align="center"  id="td_<?=$v1?>-<?=$v[ 'time']?>" bgcolor="<?=$bgcolor?>">
			                         <?if(empty($courseTimeData[$v1][$v['time']][ 'status'])){?>           
			    						<input type="checkbox" name="<?=$v1?>" class="input <?=$v1?>" value="<?=$v1?>-<?=$v[ 'time']?>"/>
			    					<?}else{?>
			                             <? if ($courseTimeData[$v1][$v['time']][ 'status']==TEACHER_CLASS_STATUS_NOTBOOKING){ $checked='checked="checked"'; ?>    					
			    						<input type="checkbox" name="<?=$v1?>" class="input <?=$v1?>"  <?=$checked?> value="<?=$v1?>-<?=$v[ 'time']?>"/>
			    						<?}?> 
				                       <?if($courseTimeData[$v1][$v['time']][ 'status']==TEACHER_CLASS_STATUS_BOOKING){ echo "<font color=\"blue\">".Common::_t('Booked')."</font>";}?>
				                       <?if($courseTimeData[$v1][$v['time']][ 'status']==TEACHER_CLASS_STATUS_CLASSED){ echo "<font color=\"green\">".Common::_t('Classed')."</font>";} ?>
			    					<?}?>
                                </td>
                                <?}?>
                        </tr>
                        <? } ?>
                       
                </table>
            </div>
        </div>
        <?$page_message = common::_t('page_message');?>
        <script>
        	//var checked_confirm_list =new Array();
            $('.input').change(
            function() {
                var value_flg = $(this).val();
                if (this.checked == true) {
                    type = 1;
// 	                $("#td_"+value_flg).attr('bgcolor','blue');
// 	                checked_confirm_list.push(value_flg);
                }
                else {
                    type = 0;
// 	                $("#td_"+value_flg).attr('bgcolor','#FFFFFF');
// 	                var removeItem = value_flg;
// 		            //删除元素    
// 	                checked_confirm_list = jQuery.grep(checked_confirm_list, function(value) {
// 	                	  return value != removeItem;
// 	                });
                }
//                 $("#checkbox_confirm_list").attr("value",checked_confirm_list);
                $.post(
               		"teacher_startCourse.html", {
                    time: value_flg,
                    type: type,
                    teacherId: $("#teacherId").val()
                }
                );
              }
            );
            
			function alls(name,dx){
				var checked_value_list = new Array();
				if(dx.checked===true){
					$("input[name='"+name+"']").each(  
					    function(){  
					    	$(this).attr("checked",true);
					    	$(this).css('')
					    	checked_value_list.push($(this).attr("value"));
// 					    	checked_confirm_list.push($(this).attr("value"));
// 					    	 $("#checkbox_confirm_list").attr("value",checked_confirm_list);
					    }   
					)
					type=1;
				}else{
					$("input[name='"+name+"']").each(  
					    function(){  
					    	$(this).attr("checked",false);
					    	checked_value_list.push($(this).val());

// 					    	var removeItem = $(this).val();
// 				            //删除元素    
// 			                checked_confirm_list = jQuery.grep(checked_confirm_list, function(value) {
// 			                	  return value != removeItem;
// 			                });					    	
// 					    	$("#checkbox_confirm_list").attr("value",checked_confirm_list);
					    }   
					)
					type=0;
				}
				
				$.post(
                   		"teacher_startAllCourse.html", {
                        time_list: checked_value_list,
                        type: type,
                        teacherId: $("#teacherId").val()
                    	}
                    );
			     }
		     $("#save_confirm").click(function(){
				 var checked_confirm_list =new Array();
		    	 $("input[type='checkbox']").each(function(){
				     	var checked = $(this).attr("checked");
						var value_flg =$(this).val();
				     	if(checked=='checked'){
							$("#td_"+value_flg).attr("bgcolor","#66CCCC");
							if(value_flg!='on'){
								checked_confirm_list.push(value_flg);
							}
					    }else{
							$("#td_"+value_flg).attr("bgcolor","#FFFFFF");
					   }
				 })
				$.post(
                   		"teacher_saveConfirmAllCourse.html", {
                        time_list: checked_confirm_list,
                        teacherId: $("#teacherId").val()
                    	}
                 );	
                 alert('<?=$page_message['page_message_6']?>');				 
			 })
			 
			 $("#next_button").click(function(){
					if(confirm('<?=$page_message['page_message_5']?>')){
						location.href="location.href='<?="teacher_courseArrangement.html?".ClassManager::getToos()->combinationGet('page')."&page=1 "?>'";
					}
			 })
			 
			 $("#up_button").click(function(){
					if(confirm('<?=$page_message['page_message_5']?>')){
						location.href="location.href='<?="teacher_courseArrangement.html?".ClassManager::getToos()->combinationGet('page')."&page=0 "?>'";
					}
			 })
        </script>
    </body>
</html>